import { notifyRecordMock } from './data/record'
import { isDateTimeInRange } from '../../../utils'
let notifyRecordList = notifyRecordMock(400)
export default [
  {
    url: RegExp('/system/notify-record/page' + '.*'), // 查询分页列表
    method: 'get',
    response: params => {
      return {
        code: 200,
        status: true,
        msg: '成功！',
        data: getListByPage(params)
      }
    }
  }
]

const getListByPage = params => {
  let result = notifyRecordList
  result = result.filter(item => !item.deleted)
  if (params.query.userId) {
    result = result.filter(item => item.userId === parseInt(params.query.userId))
  }
  if (params.query.userType) {
    result = result.filter(item => item.userType === parseInt(params.query.userType))
  }
  if (params.query.templateType) {
    result = result.filter(item => item.templateType === parseInt(params.query.templateType))
  }
  if (params.query.templateCode) {
    result = result.filter(item => item.templateCode.indexOf(params.query.templateCode) !== -1)
  }
  if (params.query.create_time && params.query.create_time.length !== 0) {
    result = result.filter(item => isDateTimeInRange(params.query.create_time[0], params.query.create_time[1], item.create_time))
  }
  return {
    list: result.slice(parseInt(params.query.pageSize) * (parseInt(params.query.pageIndex) - 1), parseInt(params.query.pageSize) * (parseInt(params.query.pageIndex) - 1) + parseInt(params.query.pageSize)),
    total: result.length
  }
}
